import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    proxy: {
      // 代理SignalR Hub请求
      '/inventoryHub': {
        target: 'https://localhost:65527',
        changeOrigin: true,
        secure: false, // 忽略SSL证书验证
        ws: true, // 启用WebSocket代理
        configure: (proxy, _options) => {
          proxy.on('error', (err, _req, _res) => {
            console.log('SignalR代理错误:', err);
          });
          proxy.on('proxyRes', (proxyRes, req, _res) => {
            console.log('SignalR代理响应:', req.method, req.url, proxyRes.statusCode);
          });
        },
      },
      '/statisticsHub': {
        target: 'https://localhost:65527',
        changeOrigin: true,
        secure: false, // 忽略SSL证书验证
        ws: true, // 启用WebSocket代理
        configure: (proxy, _options) => {
          proxy.on('error', (err, _req, _res) => {
            console.log('统计SignalR代理错误:', err);
          });
          proxy.on('proxyRes', (proxyRes, req, _res) => {
            console.log('统计SignalR代理响应:', req.method, req.url, proxyRes.statusCode);
          });
        },
      }
    }
  }
})
